/*
 * SubContainer.java
 *
 * Created on 09 December 2007, 15:43
 *
 */

package net.ubinow.mflex.baseui;


import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import net.ubinow.mflex.util.Constants;

/**
 * a sub widget container that allows the user to add a sub container to a widgetcontainer to change the layout for 'this' containers 
 * widgets
 * @author Josh
 */
public class SubContainer extends AbsWidget {
    
    private WFont _font  = null; 
    private int _layout = Constants.LAYOUT_FLOW;
    private AbsWidget[] _widgets = null;
    private int _selectedIndex = 0;
    private int _nextWidgetIndex = 0;
    
    /** Creates a new instance of SubContainer */
    public SubContainer( String id, WFont defaultFont, int layout ) {
        _id = id; 
        _font = defaultFont;        
        _layout = layout;
    }
    
    public SubContainer( String id, WFont defaultFont, int layout, AbsWidget[] widgets ){
        this( id, defaultFont, layout );
        _widgets = widgets;
        
        initWidgets();
    }
    
    private void initWidgets(){
        
    }
    
    public void addWidget( AbsWidget widget ){
        
    }
    
    public void removeWidget( AbsWidget widget){
        
    }
    
    public AbsWidget getWidget( String id ){
        if( _widgets == null || _widgets.length == 0 )
            return null;
        
        for( int i=_nextWidgetIndex; i>=0; i-- ){
            if( _widgets[i] != null && _widgets[i].getID().equalsIgnoreCase( id ) )
                return _widgets[i];
        }
        
        return null;
    }
    
    public AbsWidget getWidget( int index ){
        if( _widgets == null || index < 0 || index >= _widgets.length )
            return null;
        
        return _widgets[index];
    } 
    
    public AbsWidget getSelectedWidget(){
        return getWidget( _selectedIndex );
    }

    //<editor-fold defaultstate="collapsed" desc="AbsWidget methods">
    
    protected void setWidgetType() {
    }

    public void setBG(Image bg) {
    }

    public void setBG(int colour) {
    }

    public void cycle() {
    }

    public void paint(Graphics g, int offsetX, int offsetY, int layer) {
    }

    public boolean handleKeyPressed(int action, int keyCode) {
        return false; 
    }

    public boolean handleKeyReleased(int action, int keyCode) {
        return false; 
    }
    
    //</editor-fold>
    
}
